package com.kede.app.rest;

import com.kede.annotation.Log;
import com.kede.app.domain.LeescoreGoodTypeIds;
import com.kede.app.service.LeescoreGoodTypeIdsService;
import com.kede.app.service.dto.LeescoreGoodTypeIdsQueryCriteria;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

/**
* @author Pr.li
* @date 2023-05-27
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "goodTypeIds管理")
@RequestMapping("/api/leescoreGoodTypeIds")
public class LeescoreGoodTypeIdsController {

    private final LeescoreGoodTypeIdsService leescoreGoodTypeIdsService;

    /**
     * 导出数据
     **/
    @Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('leescoreGoodTypeIds:list')")
    public void exportLeescoreGoodTypeIds(HttpServletResponse response, LeescoreGoodTypeIdsQueryCriteria criteria) throws IOException {
        leescoreGoodTypeIdsService.download(leescoreGoodTypeIdsService.queryAll(criteria), response);
    }

    /**
    * 查询goodTypeIds
    **/
    @GetMapping
    @Log("查询goodTypeIds")
    @ApiOperation("查询goodTypeIds")
    @PreAuthorize("@el.check('leescoreGoodTypeIds:list')")
    public ResponseEntity<Object> queryLeescoreGoodTypeIds(LeescoreGoodTypeIdsQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(leescoreGoodTypeIdsService.queryAll(criteria,pageable),HttpStatus.OK);
    }

    /**
    * 新增goodTypeIds
    **/
    @PostMapping
    @Log("新增goodTypeIds")
    @ApiOperation("新增goodTypeIds")
    @PreAuthorize("@el.check('leescoreGoodTypeIds:add')")
    public ResponseEntity<Object> createLeescoreGoodTypeIds(@Validated @RequestBody LeescoreGoodTypeIds resources){
        return new ResponseEntity<>(leescoreGoodTypeIdsService.create(resources),HttpStatus.CREATED);
    }


    /**
    * 修改goodTypeIds
    **/
    @PutMapping
    @Log("修改goodTypeIds")
    @ApiOperation("修改goodTypeIds")
    @PreAuthorize("@el.check('leescoreGoodTypeIds:edit')")
    public ResponseEntity<Object> updateLeescoreGoodTypeIds(@Validated @RequestBody LeescoreGoodTypeIds resources){
        leescoreGoodTypeIdsService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }


    /**
    * 删除goodTypeIds
    **/
    @DeleteMapping
    @Log("删除goodTypeIds")
    @ApiOperation("删除goodTypeIds")
    @PreAuthorize("@el.check('leescoreGoodTypeIds:del')")
    public ResponseEntity<Object> deleteLeescoreGoodTypeIds(@RequestBody Integer[] ids) {
        leescoreGoodTypeIdsService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }




    @GetMapping("getAllByGoodId")
    public ResponseEntity getAllByGoodId(Integer goodId){
        return new ResponseEntity(leescoreGoodTypeIdsService.getAllByGoodId(goodId),HttpStatus.CREATED);
    }
}